#!/usr/bin/env python3.2
# Filename: dice.py

import random

global die, keep, rollAgain
play = True
keep = True # May want to change name?
rollAgain = True

die = [[1,0],[2,0],[3,0],[4,0],[5,0],[6,0]] #Six dice. [Die #, 0=keep / 1=roll again]

def initRoll(): #Initialize the first random throw
    for i in range(6):
        n = i+1 # n represents i+1 f r dice ID - remove line - TESTING
        die[i][0] = random.randint(1,6)
#        print('Die %d: ' % n, die[i][0], end='\n') # remove line - TESTING
#        die[i][1] = 1 # default die to 'roll again' ???    

def roll(): #Reroll chosen dice only
    for i in range(6):
        if die[i][1] == 1:
            die[i][0] = random.randint(1,6)
            die[i][1] = 0
    
def displayDice(): # will need a lot of work!
    print('\nYour dice are: ')
    for i in range(6):
        n = i+1 # n = iteration + 1 for dice ID
        print('Die %d: ' % n, die[i][0], end='\n')

def keepDice(): # Choose which dice to keep or reroll
    print('Which dice would you like to hold? (Seperate w/ commas)')
    hold = input(': ')
    for i in range(len(hold)):
        die[hold][1] = 0

def keepCheck():
    rollAgain = False
    for i in range(6):
        if die[i][1] == 1:
            rollAgain = True
    return rollAgain
    
#def score():


print('INITIAL VALUES: ', die, '\n') # remove line - TESTING

initRoll()

while play == True:
    displayDice()
    while rollAgain == True:
        keepDice()
        keepCheck()
        if rollAgain == False: break
        roll()
        displayDice()

    print("rollAgain now = False")
    playAgain = input("Would you like to play again? ")
    if playAgain == 'n': play = False

